<?php
/**
 * Created by PhpStorm.
 * User: ASUS
 * Date: 2020/9/27
 * Time: 16:02
 */

namespace app\pcapi\controller;

//支付管理
class Payment extends Base
{
    /**
     * @author ASUS
     * @date 2020-09-27 16:03
     * 代付记录
     */
    public function dfList()
    {
        $where = [];
        $add_time = input("add_time");//创建时间,
        if(!empty($add_time)){
            $where[] = ["add_time",'>=',$add_time["start_time"]];
            $where[] = ["add_time",'<=',$add_time["end_time"]];
        }
        $orderno = input("orderno");//订单号,
        if(!empty($orderno)){
            $where[] = ['orderno','=',$orderno];
        }
        $df_orderno = input("df_orderno");//代付订单号,
        if(!empty($df_orderno)){
            $where[] = ['df_orderno','=',$df_orderno];
        }
        $status = input("status");//订单号
        if($status!==null){
            $where[] = ['status','=',$status];
        }
        if(empty($where)){
            $start = strtotime(date("Y-m-d 00:00:00"));
            $end = strtotime(date("Y-m-d 23:59:59"));
            $where[] = ["add_time",'>=',$start];
            $where[] = ["add_time",'<=',$end];
        }
        $cache = cache(input("admin"));
        if($cache["id"]!=1) {//超管
            $where[] = ["admin_id","=",$cache["id"]];
        }
        $total = db("df")->where($where)->sum("df_amount");
        $page =    input('page',1);//分页，开始页数
        $limit = input('limit',10);//每页的条数
        $sort = input("sort")?input("sort"):["key"=>"add_time","value"=>"desc"];//排序
        $start = ($page-1) * $limit;//分页起始位置
        $list = db("df")->where($where)->limit($start,$limit)->order($sort["key"],$sort["value"])->select();
        $count = db("df")->where($where)->count();
        $data = [
            'list'=>$list,
            'count'=>$count,
            'total'=>$total
        ];
        api_return(200,"成功",$data);
    }
    /**
     * @author ASUS
     * @date 2020-09-27 16:03
     * 导出代付记录
     */
    public function exportDfList()
    {
        $where = [];
        $add_time = input("add_time");//创建时间,
        if(!empty($add_time)){
            $where[] = ["add_time",'>=',$add_time["start_time"]];
            $where[] = ["add_time",'<=',$add_time["end_time"]];
        }
        $orderno = input("orderno");//订单号,
        if(!empty($orderno)){
            $where[] = ['orderno','=',$orderno];
        }
        $df_orderno = input("df_orderno");//订单号,
        if(!empty($df_orderno)){
            $where[] = ['df_orderno','=',$df_orderno];
        }
        $status = input("status");//订单号
        if($status!==null){
            $where[] = ['status','=',$status];
        }
        if(empty($where)){
            $start = strtotime(date("Y-m-d 00:00:00"));
            $end = strtotime(date("Y-m-d 23:59:59"));
            $where[] = ["add_time",'>=',$start];
            $where[] = ["add_time",'<=',$end];
        }
        $cache = cache(input("admin"));
        if($cache["id"]!=1) {//超管
            $where[] = ["admin_id","=",$cache["id"]];
        }
        $list = db("df")->where($where)->select();
        api_return(200,"成功",$list);
    }
    /**
     * @author ASUS
     * @date 2020-09-27 16:09
     * 支付记录
     */
    public function zfList()
    {
        $where = [];
        $add_time = input("add_time");//创建时间,
        if(!empty($add_time)){
            $where[] = ["add_time",'>=',$add_time["start_time"]];
            $where[] = ["add_time",'<=',$add_time["end_time"]];
        }
        $orderno = input("orderno");//订单号,
        if(!empty($orderno)){
            $where[] = ['orderno','=',$orderno];
        }
        $zf_orderno = input("zf_orderno");
        if(!empty($zf_orderno)){
            $where[] = ['zf_orderno','=',$zf_orderno];
        }
        $username = input("username");
        if(!empty($username)){
            $where[] = ['username','=',$username];
        }
        $telephone = input("telephone");
        if(!empty($telephone)){
            $where[] = ['telephone','=',$telephone];
        }
        $status = input("status");//订单号
        if($status!==null){
            $where[] = ['status','=',$status];
        }
        $zf_code = input("zf_code");//clabe账号
        if(!empty($zf_code)){
            $where[] = ['zf_code','=',$zf_code];
        }
        if(empty($where)){
            $start = strtotime(date("Y-m-d 00:00:00"));
            $end = strtotime(date("Y-m-d 23:59:59"));
            $where[] = ["add_time",'>=',$start];
            $where[] = ["add_time",'<=',$end];
        }
        $cache = cache(input("admin"));
        if($cache["id"]!=1) {//超管
            $where[] = ["admin_id","=",$cache["id"]];
        }
        $page = input('page',1);//分页，开始页数
        $limit = input('limit',10);//每页的条数
        $sort = input("sort")?input("sort"):["key"=>"add_time","value"=>"desc"];//排序
        $start = ($page-1) * $limit;//分页起始位置
        $list = db("zf")
            ->where($where)
            ->limit($start,$limit)
            ->order($sort["key"],$sort["value"])
            ->select();
        $count = db("zf")->where($where)->count();
        $data = [
            'list'=>$list,
            'count'=>$count,
        ];
        api_return(200,"成功",$data);
    }
    /**
     * @author ASUS
     * @date 2020-10-30 12:05
     * 导出支付记录
     */
    public function exportZfList()
    {
        $where = [];
        $add_time = input("add_time");//创建时间,
        if(!empty($add_time)){
            $where[] = ["add_time",'>=',$add_time["start_time"]];
            $where[] = ["add_time",'<=',$add_time["end_time"]];
        }
        $orderno = input("orderno");//订单号,
        if(!empty($orderno)){
            $where[] = ['orderno','=',$orderno];
        }
        $zf_orderno = input("zf_orderno");
        if(!empty($zf_orderno)){
            $where[] = ['zf_orderno','=',$zf_orderno];
        }
        $username = input("username");
        if(!empty($username)){
            $where[] = ['username','=',$username];
        }
        $telephone = input("telephone");
        if(!empty($telephone)){
            $where[] = ['telephone','=',$telephone];
        }
        $zf_code = input("zf_code");//clabe账号
        if(!empty($zf_code)){
            $where[] = ['zf_code','=',$zf_code];
        }
        $status = input("status");//订单号
        if($status!==null){
            $where[] = ['status','=',$status];
        }
        if(empty($where)){
            $start = strtotime(date("Y-m-d 00:00:00"));
            $end = strtotime(date("Y-m-d 23:59:59"));
            $where[] = ["add_time",'>=',$start];
            $where[] = ["add_time",'<=',$end];
        }
        $cache = cache(input("admin"));
        if($cache["id"]!=1) {//超管
            $where[] = ["admin_id","=",$cache["id"]];
        }
        $list = db("zf")->where($where)->select();
        if(empty($list)){
            api_return(203,"暂无数据",[]);
        }
        api_return(200,"成功",$list);
    }
}